<?php
class BaseController extends CController
{
    public $breadcrumbs = array();
    private $_assetsBase;
    public $lang;
    public $actionTitle;
    public $rightMenu;
    
    public function init() {
        if (Yii::app()->params['bootstrap']==true){
            Yii::app()->bootstrap->registerAllCss();
            Yii::app()->bootstrap->registerCoreScripts();
        }
        parent::init();
    }

    // флеш-нотис пользователю
    public function getNotice()
    {
        return $this->widget('application.widgets.PNotify.PNotify',array( 
                                        'setFlash' => false,
        ));	
    }

    
    public function setNotice($message)
    {
        $this->widget('application.widgets.PNotify.PNotify',array( 
                                        'message'=>   $message,
                                        'setFlash' => true,
                                  ));	
    }

        
    
    public function getAssetsBase()
    {
        if ($this->_assetsBase === null) {
            $this->_assetsBase = Yii::app()->assetManager->publish(
                Yii::getPathOfAlias('theme_assets'),
                false,
                -1,
                YII_DEBUG
            );
        }
        return $this->_assetsBase;
    }
    
    
        //Мультиязычность
    public function __construct($id, $module = null) {
        parent::__construct($id, $module); 
        if (isset($_POST['language'])) {
            $lang = $_POST['language'];
            $MultilangReturnUrl = $_POST[$lang];
            $this->redirect($MultilangReturnUrl);
        }
        // Set the application language if provided by GET, session or cookie
        if (isset($_GET['language'])) {
            Yii::app()->language = $_GET['language'];
            Yii::app()->user->setState('language', $_GET['language']);
            $cookie = new CHttpCookie('language', $_GET['language']);
            $cookie->expire = time() + (60 * 60 * 24 * 365); // (1 year)
            Yii::app()->request->cookies['language'] = $cookie;
        } else if (Yii::app()->user->hasState('language'))
            Yii::app()->language = Yii::app()->user->getState('language');
        else if (isset(Yii::app()->request->cookies['language']))
            Yii::app()->language = Yii::app()->request->cookies['language']->value;
        $this->lang = Yii::app()->language;
    }
    
    public function createMultilanguageReturnUrl($lang = 'en') {
        if (count($_GET) > 0) {
            $arr = $_GET;
            $arr['language'] = $lang;
        }
        else
            $arr = array('language' => $lang);
        return $this->createUrl('', $arr);
    }
    
    
    

}
?>
